# -*- coding: utf-8 -*-
import scrapy


class TtSpider(scrapy.Spider):
    name = 'tt'
    allowed_domains = ['hr.tencent.com']
    start_urls = ['https://hr.tencent.com/position.php']

    def parse(self, response):
        tr_list = response.xpath('//table[@class="tablelist"]/tr')[1:-1]
        for tr in tr_list:
            item = {}
            item['work'] = tr.xpath('./td[1]/a/text()').extract_first()
            item['href'] = tr.xpath('./td[1]/a/@href').extract_first()
            item['class'] = tr.xpath('./td[2]/text()').extract_first()
            item['num'] = tr.xpath('./td[3]/text()').extract_first()
            item['adrs'] = tr.xpath('./td[4]/text()').extract_first()
            item['time'] = tr.xpath('./td[5]/text()').extract_first()
            yield item

        next_url = response.xpath('//div[@class="pagenav"]/a[@id="next"]/@href').extract_first()
        if next_url != 'javascript:;':
            yield response.follow(next_url,callback=self.parse)
